package IO;

import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.Vector;
import data.Show;
import Error.Error;

public class Read 
{
	
	@SuppressWarnings("unchecked")
	//Need a better way of reading this to remove the warning!
	public static Vector<Show>readShows()
	{
		return Read.readShows("shows");
	}
	
	@SuppressWarnings("unchecked")
	public static Vector<Show> readShows(String fileName) 
	{
		Vector<Show> shows = new Vector<Show>();
		String showsFile = SystemInfo.getApplicationDirectory() + fileName +".ssf";
		try
		{
			FileInputStream fis = new FileInputStream(showsFile);
			ObjectInputStream ois = new ObjectInputStream(fis);
			Object obj = ois.readObject();
			if(obj instanceof Vector<?>)
			{
				Vector<?> v = (Vector<?>) obj;
				if(v.size()> 0 && v.firstElement().getClass() == Show.class)
				{
					shows =(Vector<Show>) obj;
				}
			}
		} 
		catch (Exception e) 
		{
			Error.report(12);
		}
		return shows;
	}
	
}
